package com.icas.entity.databaseentity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.icas.util.Constant;
import lombok.Data;
import org.springframework.data.annotation.Id;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: tocchen
 * @Date: 2022/4/19 12:27
 * @Description 签到表信息
 **/
@Data
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class AttendSheetEntity {
    @Id
    private String id;
    private Integer date;
    private String courseName;
    private String teacherId;
    private String teacherName;
    private String school;
    private String batchId;
    /** 经度，纬度 */
    private Location location;
    private String courseId;
    /** 有效时间 */
    private Long validTime;
    /** 范围 */
    private String range;
    private List<StuAttend> stuAttend;
    private String roomId;
    private String status;

    /**
     * 赋值基本信息
     * @param courseEntity 课程实例
     * @param longitude 经度
     * @param latitude 纬度
     */
    public void setBasicInfo(AllCourseEntity courseEntity,Double longitude,Double latitude,String classRoom,Long validTime,String range){
        this.courseId = courseEntity.getId();
        this.courseName = courseEntity.getCourseName();
        this.teacherName = courseEntity.getTeacherName();
        this.teacherId = courseEntity.getTeacherId();
        this.school = courseEntity.getSchool();
        this.batchId = courseEntity.getBatchId();
        this.status = Constant.ATTEND_STATUS_END;

        this.date = Integer.parseInt(System.currentTimeMillis()/1000+"");

        this.validTime = validTime;

        this.range = range;

        this.roomId = classRoom;

        this.location = Location.getInstance(longitude,latitude);

        ArrayList<StuAttend> stuAttends = new ArrayList<>();

        for (StuList stuList : courseEntity.getStuList()){
            stuAttends.add(StuAttend.StuListGetInstance(stuList));
        }

        this.stuAttend = stuAttends;
    }

}
